<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
 * Moodle guestb block..
 */

global $CFG;
require_once("{$CFG->libdir}/formslib.php");

/*
* Класс для отображения формы сообщений
*/

class moodlebook_messageform extends moodleform {
	
	function definition() {
	
		$mform =& $this->_form;
		$mform->addElement('header','msgheader', get_string('message', 'block_guestb') 
				. $this->_customdata['messageid']);
		$mform->addElement('static', 'author', get_string('author', 'block_moodlebook'), $this->_customdata['author']);
		
		$mform->addElement('static', 'messagearea', get_string('messagearea', 'block_moodlebook'), $this->_customdata['message']);
		$mform->addElement('static', 'date', get_string('date', 'block_moodlebook'), userdate($this->_customdata['datetime']));
		$mform->setType('messagearea', PARAM_NOTAGS);
		if ($this->_customdata['buttons']) {
			$btnarray = array();
			$btnarray[] =& $mform->createElement('submit', 'commentmsg', get_string('buttoncomment', 'block_moodlebook'));
			$btnarray[] =& $mform->createElement('submit', 'editmsg', get_string('buttonedit', 'block_moodlebook'));
			$btnarray[] =& $mform->createElement('submit', 'deletemsg', get_string('buttondelete', 'block_moodlebook'));
			$mform->addGroup($btnarray, 'btnarr', get_string('actions', 'block_moodlebook'), array(' '), FALSE);
		}
		$mform->addElement('hidden', 'msgid', $this->_customdata['messageid']);
		$mform->setType('msgid', PARAM_INT);
	}	
}

/*
 * Класс для отображения формы отправки сообщений/комментариев/редактирования
*/
class moodlebook_submitform extends moodleform {

	function definition() {

		$mform =& $this->_form;
		$action = $this->_customdata['action'];
		$messageid = $this->_customdata['messageid'];
		$commentid = $this->_customdata['commentid'];

		$headmessage = '';
		$strings = array('comment'      => 'commentingmsg',
				'editmsg'      => 'editingmsg',
				'editcmt'      => 'editingcmt',
				'submitbutton' => 'sendmsg');
		
		$mform->addElement('header','displayinfo', $headmessage);
		
		//поле для ввода автора
		$mform->addElement('text', 'author', get_string('author', 'block_guestb'));
		$mform->addRule('author', null, 'required', null, 'client');
		$mform->setType('author', PARAM_NOTAGS);
		$mform->setConstant('author', $this->_customdata['author']);
		
		$mform->addElement('textarea', 'messagearea', get_string('messagearea', 'block_guestb'));
		$mform->setType('messagearea', PARAM_NOTAGS);
		$mform->addRule('messagearea', null, 'required', null, 'client');
		$mform->setConstant('messagearea', $this->_customdata['message']);
		$mform->addElement('hidden', 'action', $action);
		$mform->setType('action', PARAM_NOTAGS);
		
	}
}
	